//
//  tableViewSelector.m
//  XRSquare
//
//  Created by UaenaMo on 2018/8/7.
//  Copyright © 2018年 UaenaMo. All rights reserved.
//

#import "tableViewSelector.h"

@interface tableViewSelector ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView * tableView;
}
@end

@implementation tableViewSelector

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        tableView = [[UITableView alloc]initWithFrame:self.bounds];
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.tableFooterView = [UIView new];
        [self addSubview:tableView];
    }
    return self;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.dataArr count];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * identifer = @"cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifer];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
    }
    cell.textLabel.text = [[self.dataArr objectAtIndex:indexPath.row]objectForKey:@"string"];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [self.delegate selectedString:[[self.dataArr objectAtIndex:indexPath.row]objectForKey:@"string"] data:[self.dataArr objectAtIndex:indexPath.row]];
    self.hidden = YES;
}

-(void)setDataArr:(NSArray *)dataArr
{
    _dataArr = dataArr;
    [tableView reloadData];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
